<?php include $this->getViewFile('/common/Head') ?>
<body class="J_scroll_fixed">
<style>
.col-left{float:left}
.col-auto{overflow:hidden;_zoom:1;_float:left;}
.title-1{border-bottom:1px solid #eee; padding-left:5px}
.f14{font-size: 14px}
.lh28{line-height: 28px}
.blue,.blue a{color:#004499}
.gray4,a.gray4{color:#999;}
.lh22{line-height: 22px}
.lh25{line-height: 25px}
</style>
<div class="wrap J_check_wrap">
  <?php include $this->getViewFile('/common/Nav') ?>
  <div class="h_a">查找</div>
  <form method="post" action="" id="searchForm">
    <div class="search_type cc mb10">
      <div class="mb10"> 
      <?php
	  if(RBAC::authenticate('index') && ACTION_NAME == 'index'){
	  ?>
        状态：<?php echo Form::select(GoodsBmModel::model()->getStatusTags(),$status,'name="status"','全部') ?>
        操作人：
        <?php
		$adminList = array();
		foreach(AdminUser::model()->getUserList() as $rs){
			$adminList[$rs['admin_id']] = $rs['real_name'];
		}
		echo Form::select($adminList,$admin_id,'name="admin_id"','全部');
		?>
      <?php
	  }
	  ?>
      <?php
	  //付款商品
	  if(RBAC::authenticate('pay') && ACTION_NAME == 'pay'){
	  ?>
        状态：<?php echo Form::select(GoodsBmModel::model()->getStatusTags(),$status,'name="status"','全部') ?> 付款状态：<?php echo Form::select(array(1=>'等待付款',2=>'已付款','-1'=>'退款中','-2'=>'已退款'),$paystatus,'name="pay_status"','全部') ?>
      <?php
	  }
	  ?>
        上架时间：
        <input type="text" name="start_time" class="input length_2 J_date" value="<?php echo $start_time?>" placeholder="选择起始时间">
        -
        <input type="text" class="input length_2 J_date" name="end_time" value="<?php echo $end_time?>" placeholder="选择结束时间">
        报名时间：
        <input type="text" name="add_start_time" class="input length_2 J_date" value="<?php echo $add_start_time?>" placeholder="选择起始时间">
        -
        <input type="text" class="input length_2 J_date" name="add_end_time" value="<?php echo $add_end_time?>" placeholder="选择结束时间">
       
       </div>
       <div class="mb10">
        栏目：
        <select class="select_2" name="cat_id">
          <option value='0'>不限栏目</option>
          <?php  echo CategoryModel::model()->htmlCategorySelectOption($cat_id); ?>
        </select>
        关键字：<?php echo Form::select(array(1=>'商品ID',2=>'商品名称',3=>'商品旺旺'),$type,'name="type"') ?>
        <input type="text" class="input length_2" name="keyword" style="width:200px;" value="<?php echo $keyword?>" placeholder="请输入搜索内容...">
        <button class="btn">搜索</button>
      </div>
      <div class="mb10">
      <?php
	  if(ACTION_NAME == 'check'){
		  $where =  array(
		      'admin_id' => 0,
			  'status' => 0,
		  );
		  if($cat_id){
			  $where['cat_id'] = $cat_id;
		  }
		  $dcount = GoodsBmModel::model()->count(GoodsBmModel::model()->where($where));
	  ?>
      <a href="<?php echo AdminBase::U("check",array('getcheck'=>1,'cat_id'=>$cat_id)) ?>"><b><font color="#FF0000">点击获取新的需要审核的宝贝数据</font></b></a>
      (当前待审核总数：<font color="#FF0000"><?php echo $dcount; ?></font>)
      <?php
	  }
	  ?>
      </div>
    </div>
  </form>
  <div class="mb10"> 共有 ( <b><?php echo $count; ?></b> ) 个宝贝</div>
  <form name="myform" action="<?php echo AdminBase::U("public_check") ?>" method="post" class="J_ajaxForm">
    <div class="table_list">
      <table width="100%" cellspacing="0">
        <thead>
          <tr>
            <td width="50" align="center"><input type="checkbox" class="J_check_all" data-direction="x" data-checklist="J_check_x">
              全选</td>
            <td width="100" align="center">商品ID</td>
            <td align="center">商品报名信息</td>
            <td width="100" align="center">商品状态</td>
            <td width="200" align="center">管理操作</td>
          </tr>
        </thead>
        <tbody>
          <?php
		  foreach($data as $rs){
		  ?>
            <tr id="gbinfo_<?php echo $rs->goods_id;?>">
              <?php include $this->getViewFile('public_load'); ?>
            </tr>
          <?php
		  }
		  ?>
        </tbody>
      </table>
      <div class="p10">
        <div class="pages"><?php echo $Page;?></div>
      </div>
    </div>
    <div class="btn_wrap">
      <div class="btn_wrap_pd">
        <label class="mr20"><input type="checkbox" class="J_check_all" data-direction="y" data-checklist="J_check_y">全选</label>
        <select name="batch_type">
            <option value="0">请选择</option>
            <option value="1">通过</option>
            <option value="2">不通过</option>
        </select>
        <input type="text" name="batch_note" class="input length_4" value="" id="note_err" style="display:none" placeholder="不通过原因">
        <button class="btn" type="submit" data-action="<?php echo AdminBase::U("public_check") ?>">确认</button>
      </div>
    </div>
  </form>
</div>
<script src="<?php echo $staticUrl; ?>statics/js/common.js"></script>
<script>
//加载信息
function loadGoods(goods_id) {
        $.get('<?php echo AdminBase::U("public_load") ?>', {
            goods_id: goods_id
        }, function(data) {
            if (data != '') {
                $("#gbinfo_" + goods_id).html(data);
                changes();
            }
        });
}
//快速编辑
function fastEdit(gid) {
    Wind.use("artDialog", "iframeTools", function() {
        var dialog = art.dialog({
            title: '快速编辑',
            id: 'fastEdit',
            lock: true,
            fixed: true,
            width: 600,
            height: 460,
            background: "#CCCCCC",
            padding: '5px 5px',
            opacity: 0
        });
        $.get('<?php echo AdminBase::U("editor") ?>', {
            ajax: 1,
            goods_id: gid
        }, function(data) {
            if (data == 'no') {
                alert('该报名信息不存在！');
                return false;
            } else if (data == 'status') {
                alert('该商品已经审核通过，需要修改请到商品管理中修改！');
                return false;
            }
            dialog.content(data);
        });
        /*art.dialog.open('<?php echo AdminBase::U("editor") ?>?ajax=1&goods_id='+gid, {
            title: '快速编辑',
            id: 'fastEdit',
            lock: true,
            fixed: true,
			width:600,
			height:560,
            background: "#CCCCCC",
            opacity: 0
        });*/
    });
}

//绑定事件
function changes() {
    if ($('a.J_ajax_notice').length) {
        Wind.use('artDialog', 'iframeTools', function() {
            $('.J_ajax_notice').on('click', function(e) {
                e.preventDefault();
                var url = $(this).attr('href');
                var product_id = $(this).data('product_id');
                var dialog = art.dialog({
                    title: '信息通知',
                    id: 'notice',
                    lock: true,
                    fixed: true,
                    width: 600,
                    height: 70,
                    background: "#CCCCCC",
                    padding: '5px 5px',
                    opacity: 0,
                    button: [{
                        name: '确定',
                        callback: function() {
                            var notice = $('form#notice textarea[name="notice"]').val();
                            if (notice == '') {
                                alert('信息内容不能为空！');
                                return false;
                            }
                            $.getJSON(url, {
                                notice: notice
                            }, function(data) {
                                alert(data.info);
                                if (data.status) {
                                    art.dialog.list['notice'].close();
                                }
                                return true;
                            });
                            return false;
                        },
                        focus: true
                    }]
                });
                var data = '<div style="overflow:hidden;padding: 5px; ">\
				<form action="<?php echo AdminBase::U("notice") ?>" method="post" id="notice">\
				<div class="table_full">\
				  <table width="100%" class="table_form contentWrap">\
				     <tbody>\
					 <tr>\
					 <th width="80">信息内容</td>\
					 <td><textarea type="text" name="notice" cols="60" rows="3" style="height:50px;width:400px;">亲，您的商品(' + product_id + ')已经进入初审阶段，请到“报名查询”页面查询商品审核进展（查询后有审核人员旺旺），并联系洽谈。</textarea></td>\
					 </tr>\
					 </tbody>\
				   </table>\
				</div>\
				</form>\
				</div>';
                dialog.content(data);
            });
        });
    }
    //点击进行审核，
    if ($('.J_ajax_admin_check').length) {
        $('.J_ajax_admin_check input').click(function() {
            var obj = $(this).parent().parent();
            var gid = obj.data('gid');
            Wind.use("artDialog", function() {
                $.get('<?php echo AdminBase::U("admin_check") ?>', {
                    goods_id: gid
                }, function(data) {
                    if (data.status) {
                        loadGoods(gid);
                    } else {
                        art.dialog({
                            icon: 'error',
                            content: data.info
                        });
                    }
                }, 'json');
            });
        });
        $('.J_ajax_admin_check select').change(function() {
            var goods_id = $(this).data('goods_id');
            var admin_id = $(this).val();
            if (goods_id > 0 && admin_id > 0) {
                Wind.use("artDialog", function() {
                    $.get('<?php echo AdminBase::U("admin_check") ?>', {
                        goods_id: goods_id,
                        admin_id: admin_id
                    }, function(data) {
                        if (data.status) {
                            art.dialog.tips('修改成功！', 1.5);
                            loadGoods(goods_id);
                        } else {
                            art.dialog.tips(data.info, 1.5);
                        }
                    }, 'json');
                });
            }
        });
    }
}

$(function() {
    changes();
    //只显示本人正在审核的和未审核的报名商品
    if ($('input#J_mycheck').length) {
        $('input#J_mycheck').click(function() {
            $('#searchForm').submit();
        });
    }
    $('select[name="batch_type"]').change(function() {
        if ($(this).val() == 2) {
            $('#note_err').show();
        } else {
            $('#note_err').hide();
        }
    });

    $('.J_ajax_admin_check_delivery').click(function() {
        var url = $(this).attr('href');
        var goods_id = $(this).data('goods_id');
        //console.log(url);return false;
        Wind.use("artDialog", function() {
            $.get(url, {}, function(data) {
                if (data.status) {
                    loadGoods(goods_id);
                } else {
                    art.dialog({
                        icon: 'error',
                        content: data.info
                    });
                }
            }, 'json');
        });
        return false;
    });    
    //查看历史报名的次数，上架的次数及详细信息
    $(".showNumber").click(function() {
        var goods_id = $(this).data('goods_id');
        var obj = $(this);
        if (!goods_id) {
            alert('访问错误');
            return false;
        }
        $.getJSON('<?php echo $this->createUrl("public_opengoodslist") ?>', {
            goods_id: goods_id,
            count: 1
        }, function(data) {
            var shangjia_number = data.status_shangjia;
            var status_baoming = data.status_baoming;
            obj.parent().html("<span style='color:#999;font-size:11px'>报名历史次数：<a data-goods_id='" + goods_id + "' href='javascript:void(0)' class='show_baoming'>" + status_baoming + "</a>，上线历史次数：<a data-goods_id='" + goods_id + "' href='javascript:void(0)' class='show_shangjia'>" + shangjia_number + "</a></span>");
        })
    })
	//历史报名，上架记录查询
    $(document).on("click", ".show_shangjia,.show_baoming", function() {
        var obj = $(this);
        if (parseInt(obj.html()) == 0) {
            //alert('找不到记录');
            return false;
        }
        var status = '';
        var goods_id = obj.data('goods_id');
        if (obj.hasClass('show_baoming')) {
            status = '';
        } else {
            status = 1;
        }
        Wind.use('artDialog', 'iframeTools', function() {
            var dialog = art.dialog.open('<?php echo $this->createUrl("public_opengoodslist") ?>?goods_id=' + goods_id + '&status=' + status, {
                title: '信息列表',
                id: 'notice',
                lock: true,
                fixed: true,
                width: 700,
                height: 500,
                background: "#CCCCCC",
                cancelDisplay: true
            });
        });
    })

});
</script>
</body>
</html>